<extend name="common:commonTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">商品</a> <a class="current" href="#">商品管理</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">商品编码:</label>
								<div class="controls">
									<input type="text" id="style_sn" name="style_sn"/>
								</div>
							</div>
								<div class="control-group">
								<label class="control-label">商品名称:</label>
								<div class="controls">
									<input type="text" id="style_name" name="style_name"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">sku渠道:</label>
								<div class="controls">
								<select id="sku_channel" name="sku_channel" style="width:220px;" >
									<option value="">--ALL--</option>
									<option value="1">淘宝</option>
									<option value="2">京东</option>
									<option value="3">官网</option>
									<option value="5">英雄会O2O</option>
									<option value="6">村淘</option>
									<option value="8">大客户</option>
								</select>
								</div>
							</div>
							
							<div class="form-actions">
								<input id="btn_style_search" type="button" class="btn btn-success" value="搜索">
								<a target="_blank" href="/style/addStyle" style="background:red" class="btn btn-success" > 新增</a>
								
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  page_index="1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>商品编号</th>
                  <th>商品编码</th>
                  <th>商品名称</th>
                  <th>商品简介</th>
                  <th>sku渠道</th>
                  <th>商品渠道名称</th>
                  <th>上架时间</th>
                  <th>市场价</th>
                  <th>市场价</th>
                  <th>最低销售单价</th>
                  <th>最高销售单价</th>
                  <th>sku总库存</th>
                  <th>是否实体商品</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
      <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" id="page_input" style="width:20px;" class="ui-state-default"></span>

        			<a class="fg-button ui-button ui-state-default" id="page_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
       </div>
    </div>
  </div>

</div>
</block>

<block name="js_content">
<script>
StyleInfoPage = {
		'BindEvent': function(){
			$('#btn_style_search').bind('click', function(){
				 var page_index = 1;
				 StyleInfoPage.Search(page_index);
				
			});
			
			$('#page_jump').bind('click', function(){
				
				 var page_index = $('#page_input').val();
				 var total_page = $('#total_page').text();
				 var curr_page = $('#curr_page_index').text();
				 
					
				 if (page_index == ''||page_index == undefined||page_index == null) {
	                    page_index = curr_page;
	                }
				 if(parseInt(page_index) <= 0 || parseInt(page_index) > parseInt(total_page)  ){
					 page_index =1;
				 }
				 
				 
				 StyleInfoPage.Search(page_index);
			});
			
			 $(".first,.previous,.last,.next").bind('click', function () {
	                if ($(this).hasClass('ui-state-disabled')) {
	                    return false;
	                }

	                var page_index = $(this).attr('page_index');
	                if (page_index == undefined) {
	                    page_index = 1;
	                }
	                //page_index = 1;
	                StyleInfoPage.Search(page_index);
	            });
		},
		'Search': function (page_index) {
            var condition = $("#basic_validate").serialize();
            condition += "&pageSize=20&index="+page_index;

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/style/queryStyleByPara',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                	StyleInfoPage.BindTable(data.Result, page_index);
                	StyleInfoPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
		'BindTable': function(result,page_index){
			lst_style = result.datas;
			if(lst_style.length == 0){				
				
				$('#search_result tbody').html('');
				var msg ="<tr><td colspan='15' style='text-align:center'>暂无数据!</td></tr>";	
							
				$('#search_result tbody').append(msg);	
				return;
			};
			var html = '';
			for(var index in lst_style){
				var style_en = lst_style[index];
				var tr_html = "<tr>";
				tr_html += "<td>" + style_en.style_id+"</td>";
				tr_html += "<td>" + style_en.style_sn+"</td>";
				tr_html += "<td>" + style_en.style_name + "</td>"
				tr_html += "<td>" + style_en.style_brief + "</td>"
				tr_html += "<td>" + style_en.sku_channel_text + "</td>"
				tr_html += "<td>" + style_en.sku_channel_name+"</td>";
				tr_html += "<td>" + style_en.sale_date+"</td>";
				tr_html += "<td>" + style_en.market_price + "</td>"
				tr_html += "<td>" + style_en.shop_price + "</td>"
				tr_html += "<td>" + style_en.sale_min_price + "</td>"
				tr_html += "<td>" + style_en.sale_max_price+"</td>";
				tr_html += "<td>" + style_en.sku_stock+"</td>";
				tr_html += "<td>" + style_en.is_real + "</td>"
				tr_html += "<td>" + style_en.status_text + "</td>"
				tr_html += "<td>"+"<a style='color:blue;' href='/style/detailStyle?style_id="+ style_en.style_id + "'>查看详情</a></td>"
				tr_html += "</tr>";
				html += tr_html;
			} 
			$('#search_result tbody').html('');
			$('#search_result tbody').append(html);
			
		},
		'SetPageIndex': function (total_page, total_count, page_index) {
            $('#total_count').text(total_count);
            $('#total_page').text(total_page);
            $('#curr_page_index').text(page_index);
            page_index = parseInt(page_index);
            total_count =parseInt(total_count);
			
			if(total_page == 0){
				$('#paging .last').addClass('ui-state-disabled');
				$('#paging .next').addClass('ui-state-disabled');
				$('#paging .first').addClass('ui-state-disabled');
				$('#paging .previous').addClass('ui-state-disabled');
				return;
			}
            if (page_index == 1) {
                $('#paging .first').addClass('ui-state-disabled');
                $('#paging .previous').addClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', 1);
            }
            else {
                $('#paging .first').removeClass('ui-state-disabled');
                $('#paging .previous').removeClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', page_index - 1);
            }

            if (total_page == page_index) {
                $('#paging .last').addClass('ui-state-disabled');
                $('#paging .next').addClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', total_page);
            }
            else {
                $('#paging .last').removeClass('ui-state-disabled');
                $('#paging .next').removeClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', page_index + 1);
            }

        },

		'ConvertStrNull':function(obj){
			
			if(obj == null){
				return '';
			}
			else{
				return obj;
			}
		},
		'ConvertSignStatus':function(obj){
			if(obj == '1'){
				return '待签约';
			}else if(obj =='2'){
				return '经销商待盖章';
			}else if(obj =='3'){
				return '已签约';
			}
		} ,		
};


$(document).ready(function(){
	StyleInfoPage.BindEvent();
});


</script>
</block>